home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Text⁄Files
/
Writeswell Jr. 1.0.2 Master
/
Writeswell Jr. Source
/
ObOspec.c
< prev
next >
Wrap
Text File
|
1992-10-06
|
6KB
|
239 lines
/* ObOspec.c
* Routines to handle typeObjectSpecifier objects for Word Services
* ©1992 Working Software, Inc.
* This source code is copyrighted. Permission is granted to use the Word Services
* portion of the Writeswell Jr. source code in your own programs, but you
* may not distribute the Writeswell Jr. word-processor code as a
* commercial product. If you modify the code, please do not call it
* Writeswell Jr. (or Writeswell.) This will ensure that people understand the
* program and don’t have to deal with a number of different versions with
* who-knows-what going on in the code.
*
* Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
* 24 Dec 91 Mike Crawford
*/
#include <AppleEvents.h>
#include <AEObjects.h>
#include <AEPackObject.h>
#include <AERegistry.h>
#include "AppEvents.h"
#include "ObText.h"
#include "ObWind.h"
#include "ObOSpec.h"
#include "Gripe.h"
/* Given the the direct object of an event is a window token (or property thereof),
* do the requested event.
*/
OSErr DispatchOspec( AEDesc *tokenPtr,
AppleEvent *theAppleEventPtr,
AppleEvent *replyEventPtr,
long refCon )
{
OSErr err;
AEEventClass theClass;
AEEventID theID;
/* This function is only for the Core suit. Get the event ID from the appleEvent
*/
err = GetEventID( theAppleEventPtr, &theID );
switch ( theID ){
case kAEGetData:
err = OspecGetDataHandler( tokenPtr, theAppleEventPtr, replyEventPtr, refCon );
break;
default:
err = errAEEventNotHandled;
break;
}
return noErr;
}
/* The handlers for the various events */
/* Get Data */
OSErr OspecGetDataHandler( AEDesc *tokenPtr,
AppleEvent *theAppleEventPtr,
AppleEvent *replyEventPtr,
long refCon )
{
DescType propCode;
OSpecTokenBody **tokHdl;
AEDesc replyValue;
Str255 tmpStr;
OSErr err;
/* Sanity check */
if ( tokenPtr->descriptorType != typeOSpecToken ){
Gripe( "\pGot wrong token type" );
return errAEEventNotHandled;
}
tokHdl = (OSpecTokenBody**)(tokenPtr->dataHandle);
propCode = (*tokHdl)->propertyCode;
switch ( propCode ){
case typeNull:
/* This is a magic number for "Not A Property". I don't know if this
* is really kosher - gotta ask, but it is a convenience.
*/
err = CreateWindTextSpec( (*tokHdl)->theWindowPtr,
(*tokHdl)->textItem,
&replyValue );
if ( err ){
Gripe( "\pCreateTextSpecifier failed" );
return err;
}
break;
case pName:
case pBounds:
case pClass:
case pHasTitleBar:
case pIndex:
case pIsModal:
case pIsResizable:
case pIsZoomed:
case pVisible:
Gripe( "\pGot a property type we do not yet implement" );
return errAENoSuchObject;
break;
default:
Gripe( "\pUnknown property type" );
return errAENoSuchObject;
break;
}
/* At this point we have some kind of descriptor to stick in the reply */
err = AEPutParamDesc( replyEventPtr,
keyDirectObject,
&replyValue );
if ( err ){
Gripe( "\pAEPutParamDesc failed" );
return err;
}
err = AEDisposeDesc( &replyValue );
if ( err ){
Gripe( "\pAEDisposeDesc failed" );
return err;
}
return noErr;
}/* WindGetDataHandler */
/* Return an Ospec token given a window token */
pascal OSErr OspecFromWind(DescType desiredClass,
const AEDesc *container,
DescType containerClass,
DescType form,
const AEDesc *selectionData,
AEDesc *theToken,
long LongInt)
{
AEDesc longKeyData;
long count;
OSpecTokenBody tokData;
OSErr err;
/* Check that the container is what we intend. This should only happen if we
* installed the token handler incorrectly.
*/
if ( container->descriptorType != cWindow )
return errAEEventNotHandled;
/* find the text block based on the key form */
switch ( form ){
case formAbsolutePosition:
/* Make sure we really have a type long descriptor */
err = AECoerceDesc( selectionData, typeLongInteger, &longKeyData );
if ( err ){
Gripe( "\pAECoerceDesc failed" );
return err;
}
count = **(long**)(longKeyData.dataHandle);
/* We're done with the descriptor created in the coercion */
err = AEDisposeDesc( &longKeyData );
if ( err ){
Gripe( "\pAEDisposeDesc failed" );
return err;
}
/* In our particular case, we can have only one text field in our table.
* A structured document would have more, so it would need a way to locate
* the item in the table right here.
*
* It is OK to return an error - it is legitimate for the speller to
* find out how many elements we have by just asking for them until we
* run out.
*/
#ifndef HACK_OSPECS
if ( count != 1L ){
return errAENoSuchObject;
}
#else
if ( count != 1L && count != 2L ){
return errAENoSuchObject;
}
#endif
/* Actually create the token that we return */
tokData.theWindowPtr = ((WindTokenBody*)(*(container->dataHandle)))->theWindowPtr;
tokData.textItem = count;
tokData.propertyCode = typeNull; /* This means it's not a property */
err = AECreateDesc( typeOSpecToken, (Ptr)&tokData, sizeof( tokData ), theToken );
if ( err ){
Gripe( "\pAECreateDesc failed to create a token" );
return err;
}
return noErr;
break;
case formRelativePosition:
case formTest:
case formRange:
case formPropertyID:
case formName:
return errAEEventNotHandled; /* Flesh this out later */
break;
default:
Gripe( "\pGot unexpected key form" );
return errAEEventNotHandled;
}
return noErr;
}
/*
* Object counting routines.
*/
OSErr CountOSpecInWind( WindowPtr wp, long *countPtr )
{
/* For us, there can only be one object specifier in a window. If you have
* a structured document such as a spreadsheet, you should count the cells that
* are selected for spellchecking.
*/
*countPtr = 1L;
return noErr;
}